package nc.appcan.sp.servlet;

import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import nc.appcan.sp.bs.tool.AnnotateTool;
import nc.appcan.sp.nc.vo.FileURLVO;
import nc.appcan.sppub.pub.MerpZIP;
import nc.bs.framework.adaptor.IHttpServletAdaptor;
import nc.bs.logging.Logger;
import nc.bs.pub.pf.PfUtilTools;
import nc.itf.uap.pf.INCMAFileInter;

import com.alibaba.fastjson.JSON;

public class AppcanDownloadServlet extends HttpServlet implements IHttpServletAdaptor {

	private static final long serialVersionUID = 591955759856323777L;



	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doAction(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doAction(req, resp);
	}

	public void doAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Logger.init("merp");
		OutputStream out = null;
		try{		
				String pk =	request.getParameter("pk");
				String billtype  =request.getParameter("billtype");
				out = response.getOutputStream();
				INCMAFileInter handler = AnnotateTool.getFileServiceClass(billtype);
				handler.downloadNC(out, pk);
				if(out!=null)out.close();
			}catch(Exception e){
				Logger.error(e.getMessage(), e);
				e.printStackTrace();
			}finally{
				try {
					if (out != null) {
						out.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		
	}
	
}
